import { HintData } from "../../Data/HintData";
import HintPanel from "../../Panel/HintPanel";
import LanguageManager from "../../../constant/LanguageManager";

export default class HintUi extends Laya.Script {

    private parentComponent: fairygui.GComponent;

    private hintPanel: HintPanel;

    private curHintData: HintData;

    public SetData(cpm: fairygui.GComponent, curHintData: HintData, selectLevelPanel: HintPanel, index: number): void {
        this.parentComponent = cpm;
        this.hintPanel = selectLevelPanel;
        this.curHintData = curHintData;
        this.InitComponent(index);
    }

    private InitComponent(index: number) {
        this.ShowNoOpenHintBg();
        let GetHintBtn = this.parentComponent.getChild("GetHintBtn").asButton;
        let indexText = this.parentComponent.getChild("indexText").asLabel;
        indexText.text = "NO." + (index + 1);
        GetHintBtn.onClick(this, this.OnGetHintBtnClick);
    }

    private OnGetHintBtnClick() {
        this.ShowOpenHintBg();
    }

    private ShowNoOpenHintBg() {
        let noOpenHintBg = this.parentComponent.getChild("noOpenHintBg").asImage;
        noOpenHintBg.displayObject.visible = true;

        let GetHintBtn = this.parentComponent.getChild("GetHintBtn").asButton;
        GetHintBtn.displayObject.visible = true;

        let getHintText = this.parentComponent.getChild("getHintText").asLabel;
        getHintText.displayObject.visible = true;
        getHintText.text = window.gameFacade.ConfigMng.GetLanguageByKey(LanguageManager.GET_HINT);

        let openHintBg = this.parentComponent.getChild("openHintBg").asImage;
        openHintBg.displayObject.visible = false;

        let desc = this.parentComponent.getChild("desc").asLabel;
        desc.displayObject.visible = false;
        desc.text = window.gameFacade.ConfigMng.GetLanguageByKey(LanguageManager.HINT_DESC_LANGUAGE + this.curHintData.id);
    }

    private ShowOpenHintBg() {
        let noOpenHintBg = this.parentComponent.getChild("noOpenHintBg").asImage;
        noOpenHintBg.displayObject.visible = false;

        let GetHintBtn = this.parentComponent.getChild("GetHintBtn").asButton;
        GetHintBtn.displayObject.visible = false;

        let getHintText = this.parentComponent.getChild("getHintText").asLabel;
        getHintText.displayObject.visible = false;
        getHintText.text = window.gameFacade.ConfigMng.GetLanguageByKey(LanguageManager.GET_HINT);

        let openHintBg = this.parentComponent.getChild("openHintBg").asImage;
        openHintBg.displayObject.visible = true;

        let desc = this.parentComponent.getChild("desc").asLabel;
        desc.displayObject.visible = true;
        desc.text = window.gameFacade.ConfigMng.GetLanguageByKey(LanguageManager.HINT_DESC_LANGUAGE + this.curHintData.id);
    }
}